<template>
  <component
    v-if="curTemplateConfig"
    :is="allComps[layoutConfig['templateName']]"
    :layout-config="layoutConfig"
    :template-idx="templateIdx"
    v-bind="$attrs"
  ></component>
</template>
<script setup>
  import BizSearchformTablelistSimple from "./biz-searchform-tablelist-simple/index.vue";
  import BizBlankSimple from "./biz-blank-simple/index.vue";
  import {
    globalConfig,
    resourceApiAliasConfig,
    realPageFilePathKeyFuc,
    getCurResourceLastCode,
  } from "@gd-accbuild-core/config";
  import { computed } from "vue";
  import { useStore } from "@gd-accbuild-core/store/hackVueStore";
  import { getTemplateKey } from "@gd-accbuild-core/hooks/useGetCurUiTemplateInfo/utils/getPageUiTemplateMetaListAndData";
  const _store = useStore();
  const props = defineProps({
    templateIdx: {
      type: Number,
      require: true,
    },
    staticResource: {
      type: Object,
    },
  });
  const curActivedResource = computed(() => {
    if (props.staticResource) {
      return props.staticResource;
    }
    return _store.state.designerEngine.curActivedResource;
  });
  const curTemplateConfig = computed(() => {
    const uiOptionsKeyAlias = resourceApiAliasConfig["uiOptionsKeyAlias"];
    const pageUiTemplateConfigsKeyAlias = resourceApiAliasConfig["pageUiTemplateConfigsKeyAlias"];
    const resource = curActivedResource.value;
    if (
      Array.isArray(resource[uiOptionsKeyAlias]?.[pageUiTemplateConfigsKeyAlias]) &&
      resource[uiOptionsKeyAlias]?.[pageUiTemplateConfigsKeyAlias].length >= 1
    ) {
      return resource[uiOptionsKeyAlias]?.[pageUiTemplateConfigsKeyAlias][props.templateIdx];
    } else {
      return null;
    }
  });
console.log(curTemplateConfig,'curTemplateConfig=====')
  const layoutConfig = computed(() => {
    if (curTemplateConfig.value) {
      return {
        templateName: curTemplateConfig.value["templateName"],
        templateKey: getTemplateKey(curTemplateConfig.value),
        templateConfig: curTemplateConfig.value,
        _templateKey:getTemplateKey(curTemplateConfig.value,"_templateName"),
      };
    } else {
      return {};
    }
  });

  const allComps = {
    BizSearchformTablelistSimple: BizSearchformTablelistSimple,
    BizBlankSimple: BizBlankSimple,
  };
</script>
